home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Auge 4000 / Auge 4000 #15 (1988-01-22)(Amiga User Gruppe Einzugsgebiet 4000).zip / Auge 4000 #15 (1988-01-22)(Amiga User Gruppe Einzugsgebiet 4000).adf / Späße / LPem.c < prev    next >
C/C++ Source or Header  |  1988-01-20  |  5KB  |  196 lines

  1.  
  2. /* I know I stole a bunch of this source off of somebody, but I've 
  3.    forgotten who it is.  If this looks familiar, sorry, but I've
  4.    forgotten who you are.                          */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/memory.h>
  8. #include <intuition/intuition.h>
  9. #include <graphics/sprite.h>
  10. #include <exec/tasks.h>
  11.  
  12. struct Preferences MyPrefs;
  13. struct RastPort *RP;
  14. struct IntutitionBase *IntuitionBase;
  15. struct GfxBase *GfxBase;
  16. unsigned short color[3];
  17. int red[3], green[3], blue[3];
  18.  
  19. #define NUM          6
  20. #define SPRHEIGHT       16
  21. #define WORDSPERSPR     (2 * SPRHEIGHT + 4)
  22. #define ever            (;;)
  23.  
  24.  
  25. struct NewWindow windef = {
  26.         0, 15, 300, 10,
  27.         -1, -1,
  28.     CLOSEWINDOW,
  29.         REPORTMOUSE | WINDOWCLOSE | WINDOWDEPTH | WINDOWDRAG,
  30.         NULL, NULL,
  31.         (UBYTE *) "Wait...",
  32.         NULL, NULL, 0, 0, 0, 0,
  33.         WBENCHSCREEN
  34. };
  35.  
  36. struct SimpleSprite     spr[NUM];
  37. struct Window   *win;
  38. struct ViewPort *vp;
  39. UWORD           *sprbuf;
  40. UWORD           *sprites[NUM];
  41.  
  42. main (argc, argv)
  43. int argc;
  44. char *argv[];
  45. {
  46.         int i,j,  offset = 0, flag = 0;
  47.         void *msg;
  48.     BYTE Count;
  49.         openstuff ();
  50.  
  51. RP = (struct RastPort *)win.RPort;
  52. Count = 1;
  53. if (argc > 1)
  54.     {
  55.     Count = atoi(argv[1]);
  56.     if ((Count > 10) | (Count == 0))
  57.         {
  58.         printf("Usage: %s count (1-10)\n", argv[0]);
  59.          Count = 1;
  60.         };
  61.     };
  62.  
  63.  
  64. color[1] = (USHORT) MyPrefs.color17;
  65. color[2] = (USHORT) MyPrefs.color18;
  66. color[3] = (USHORT) MyPrefs.color19;
  67.  
  68. for (i = 1; i <=3; i++)
  69. {
  70. red[i] = (color[i] >> 8) & 0x0F;
  71. green[i] = (color[i] >> 4) & 0x0F;
  72. blue[i] = color[i] & 0x0F;
  73. }
  74.  
  75. for (i = 17; i < 31; i = i + 4)
  76. {
  77. SetRGB4(vp, i, red[1], green[1], blue[1]);
  78. SetRGB4(vp, i+1, red[2], green[2], blue[2]);
  79. SetRGB4(vp, i+2, red[3], green[3], blue[3]);
  80. };
  81.  
  82.         setupsprites ();
  83.  
  84.         for (i=0; i<NUM; i++) {
  85.                 if (GetSprite (&spr[i], (long) i+1) < 0)
  86.                         die ("LPem: Sprite allocation failed.");
  87.                 spr[i].x = 640 / 2;
  88.                 spr[i].y = 10;
  89.                 spr[i].height = SPRHEIGHT;
  90.                 ChangeSprite (vp, &spr[i], sprites[i]);
  91.         }
  92.  
  93.         SetWindowTitles (win, " Long Persistence Emulator ", "By Steve Tibbett");
  94.         for ever {
  95.  
  96.                 if (msg = GetMsg (win -> UserPort)) {
  97.                         ReplyMsg (msg);
  98.                         if (msg->Class == CLOSEWINDOW)
  99.                 {
  100.                 closestuff ();
  101.                 return;
  102.                 };
  103.             };
  104.                 
  105.  
  106.                 for (i=0; i<NUM; i++) 
  107.               {
  108.         for (j = 0; j < Count; j++) WaitTOF();
  109.         spr[NUM-i-1].x = (win->MouseX + win->LeftEdge + MyPrefs.XOffset);
  110.         spr[NUM-i-1].y = (win->MouseY + win->TopEdge + MyPrefs.YOffset - 1);
  111.              ChangeSprite (vp, &spr[NUM-i-1], sprites[NUM-i-1]);
  112.  
  113.             }
  114.     }
  115. }
  116.  
  117. openstuff ()
  118. {
  119. IntuitionBase = OpenLibrary ("intuition.library", 0);
  120.  
  121.     /* Geez, guys, what if Intuition isn't here?  Who cares?  We're
  122.        probably all dead anyways, if this happens... */
  123.  
  124. GfxBase = OpenLibrary ("graphics.library", 0);
  125.  
  126.     /* Ya, sure, you've pulled the Graphics.Library ROM out, right? */
  127.  
  128.         if (!(win = OpenWindow (&windef)))
  129.                 die ("LPem: No memory for window");
  130.  
  131. GetPrefs(&MyPrefs, sizeof(struct Preferences));
  132.  
  133.         vp = ViewPortAddress (win);
  134. }
  135.  
  136. closestuff ()
  137. {
  138.         register int i;
  139.  
  140.         for (i=0; i<NUM; i++)
  141.                 if (spr[i].num)
  142.                         FreeSprite ((long) spr[i].num);
  143.  
  144.         if (sprbuf)
  145.                 FreeMem (sprbuf, 2L * WORDSPERSPR * NUM);
  146.         if (win)
  147.                 CloseWindow (win);
  148.         if (GfxBase)
  149.                 CloseLibrary (GfxBase);
  150.         if (IntuitionBase)
  151.                 CloseLibrary (IntuitionBase);
  152. }
  153.  
  154. die (str)
  155. char *str;
  156. {
  157.         puts (str);
  158.         closestuff ();
  159.         exit (100);
  160. }
  161.  
  162.         int i;
  163.  
  164. setupsprites ()
  165. {
  166. /* This is what I stole.  Boy, I hope it wasn't copyrighted... */
  167.  
  168.         UWORD *cw;  
  169.         UWORD *maskp; 
  170.         UWORD *ballp, *ballp2; 
  171.         int frame, scan;
  172.  
  173.         if (!(sprbuf = AllocMem (2L * WORDSPERSPR * NUM, MEMF_CHIP)))
  174.                 die ("LPem: Can't allocate sprite buffer.");
  175.  
  176.         cw = sprbuf;    /* current position at top of buffer */
  177.         ballp = &MyPrefs.PointerMatrix[0];  /* ... top of data to be interleaved */
  178.     ballp2 = ballp;
  179.  
  180.         for (frame=0; frame<NUM; frame++) {
  181.                 maskp = 1;       /* one mask for all frames */
  182.                 sprites[frame] = cw;
  183.                 *cw++ = 0;              /* poscntl */
  184.                 *cw++ = 0;
  185.         ballp=ballp2;
  186.                 /* one word from ball0, one word from ballmask */
  187.                 for (scan=0; scan<SPRHEIGHT; scan++) {
  188.                         *cw++ = *ballp++;
  189.                         *cw++ = *ballp++;
  190.                 }
  191.                 *cw++ = 0;      /* termination */
  192.                 *cw++ = 0;
  193.         }
  194. }
  195.  
  196.